home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 43 / Mac Magazin and MacEasy Magazine CD - Issue 43.iso / Software / Entwickler / ListBox 0.4 / ListBox.h < prev    next >
Text File  |  1998-02-16  |  3KB  |  87 lines

  1. /********************
  2. ListBox - A simple replacement for the list manager
  3.  files: ListBox.h
  4.          ListBox.cpp
  5.          
  6. By Kyle Ellrott
  7.     killtherat@bigfoot.com
  8.     
  9. 2/14/98
  10.  
  11. Feel free to re-use and tear apart this code.  But if any part of it is in a program 
  12. you release please indicate my name in the credits.
  13.  
  14. Bugs:  I'm sure there are a few.  If you find any, please tell me about em.
  15. *******************/
  16.  
  17.  
  18. typedef void (*customModalFilter)(DialogPtr destDialog, EventRecord *theEvent, short *itemHit);
  19.  
  20. class ListBox {
  21. public:
  22. //Initialize
  23.     ListBox();                
  24. //Trash it
  25.     ~ListBox();                
  26.     
  27. //Pass the itemNum of something in a dialog box, and this creates the List
  28.     void SetupFromItem(DialogPtr theDialog, short itemNum);    
  29. //Pass the rectangle where you want the box
  30.     void SetupFromRect(DialogPtr theDialog, Rect *rect);
  31. //Shut it Down
  32.     void Close(void);
  33.     
  34. //Call ModalDialog if you want a stanard Modal dialog box with a list
  35. //Note, I haven't done extinsive testing with custom filters
  36. //If you want to roll your own dialog filter it's probably better if you
  37. //Pass the Events to TrackEvent() and use Draw() of the updates
  38.     void ModalDialog(customModalFilter modalFilter, DialogItemIndex * itemHit);
  39.  
  40. //TrackEvents figures out if they clicked on the List    
  41.     Boolean TrackEvent(EventRecord *theEvent);
  42.     void Draw(void);    
  43.  
  44. //Pass the restype, and it will make a list.  The item id's are the res numbers...    
  45.     void MakeResTypeList(long resType);
  46.     void AddItem(short idNum, Str255 name);
  47. //Pass the line number of the Item you want to delete
  48.     void KillLine(short lineNum);
  49. //This just kills the entire list...
  50.     void KillItemList(void);
  51. //Change the order of two lines
  52.     void SwapLines(short line1, short line2);
  53. //Find out how many items are in your list
  54.     short GetItemCount(void);
  55. //These functions effect which line is highlighted
  56.     short GetCurLine(void);
  57.     void SetCurLine(short line);
  58. //These functions effect which line is at the top of screen    
  59.     void SetTopLine(short line);
  60.     short GetTopLine(void);
  61. //This gives the ID num of the current selection    
  62.     short GetCurItem(void);
  63. //Get the ID num of any old line
  64.     short GetLineID(short lineNum);
  65. //Makes sure the ScrollBar is set up right.  You probably won't need to call it.    
  66.     void AdjustScrollBar(void);
  67. // The scroll bar is public only because the localScoll 
  68. //function needs to call this varible from a global ListBox
  69.     ControlHandle    theScrollBar;
  70. private:
  71.     struct lbItem    *items;
  72.     DialogPtr        destDialog;
  73.     Rect            destRect;
  74.     Point            itemSize;
  75.     short            topLine, curLine;
  76.     long            lastClick;
  77.     
  78. };
  79.  
  80.  
  81. typedef struct lbItem {
  82. Str255        name;
  83. short        idNum;
  84. struct lbItem    *next;
  85. }lbItem;
  86.  
  87.